package com.example.myshop.service;

import com.example.myshop.entity.Product;
import com.example.myshop.service.ex.ServiceException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
@Service
public class productservicetest {
    @Autowired
    private ProductService productService;

    @Test
    public void hotlisttest(){
        try {
            List<Product> list = productService.findHotList();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void findMarkListtest(){
        try {
            List<Product> list = productService.findMarkList();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void findpricedesc(){
        try {
            List<Product> list = productService.findDescList();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }

    }
    @Test
    public void findpriceasc(){
        try {
            List<Product> list = productService.findAscList();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }



    @Test
    public void findByTitle() {
        try {
            List<Product> list = productService.findByTitle("D");
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void findAllProducts() {
        try {
            List<Product> list = productService.findAllProducts();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }
    @Test
    public void findAllPassProducts() {
        try {
            List<Product> list = productService.findAllPassProducts();
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }
    @Test
    public void findAllProductsByBid() {
        try {
            List<Product> list = productService.findAllProductsByBid(24L);
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void findPassProductsByBid() {
        try {
            List<Product> list = productService.findPassProductsByBid(24L);
            System.out.println("count=" + list.size());
            for (Product item : list) {
                System.out.println(item);
            }
        } catch (ServiceException e) {
            System.out.println(e.getClass().getSimpleName());
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void insert(){
        Product product=new Product();
        product.setId(10000025l);
        product.setCategoryId(241l);
        product.setItemType("test圆珠笔");
        product.setTitle("test晨光a2圆珠笔中油笔水感顺滑黑色40支按动式0.7mm 40支黑色");
        product.setSellPoint("test圆珠笔中油笔水感顺滑黑色");
        product.setPrice((long) 30);
        product.setNum(99999);
        product.setImage("/images/portal/24_test/");
        product.setStatus(1);
        product.setPriority(53);
        product.setNowSellNum(41);
        product.setHistorySellNum(101);
        product.setSellPersons(101);
        product.setJudgeMark(10);
        product.setSellMethod("网上支付");
        product.setBusinessId(99999L);

        productService.insert(product);
        try {
            System.out.println("注册成功");
        } catch (ServiceException e) {
            //获取类的对象，再获取类的名称
            System.out.println(e.getClass().getSimpleName());
            //获取异常具体描述信息
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void passProjectById(){
        productService.passProjectById(1L);
    }
/*
    @Test
    public void rejectProjectById(){
        productService.rejectProjectById(100000262);
    }

    @Test
    public void passProjectByBusiness(){
        productService.passProjectByBusiness(10000023);
    }

    @Test
    public void rejectProjectByBusiness(){
        productService.rejectProjectByBusiness(10000023);
    }*/
}
